{test sqzmask16u, expmask16u, cnvmsk16uto8 macro commands } {sqzmask(in,mask,out)} var origPid, maskPid, vectPid, newPid: Integer; xlate16uto8Pid, ymin, ymax: integer; macro '[m] front image is mask'; begin maskPid := pidNumber; end; macro '[i] front image is original --input-- image'; begin origPid := PidNumber; end; macro '[v] front image is vector'; begin vectPid := PidNumber; end; macro '[o] front image is new --output-- image'; begin newPid := PidNumber; end; macro '[m] Make minimum size 16 bit vector stack'; var n: integer; front: integer; left,top,width,height: integer begin front := pidNumber; ChoosePic(maskPid); Measure; GetROI(left,top,width,height); if width = 0 then GetPicSize(width,height); n := width * height - histogram[0]; width := Sqrt(n) + 1; if width < 32 then width := 32; height := n div width + 1; SetNewSize(width * 2, height); {16 bits} MakeNewStack('minimum vector ',width,' wide ',height,' high'); vectPid := pidNumber; SelectPic(front); end; macro '[s] squeeze'; var i, n: integer; begin selectPic(origPid); if nSlices = 0 then SqzMask16u(origPid, maskPid, vectPid) else begin n := nSlices; for i := 1 to n do begin choosePic(origPid); chooseSlice(i); choosePic(vectPid); if i > nSlices then addSlice; chooseSlice(i); SqzMask16u(origPid, maskPid, vectPid) end; selectPic(vectPid); selectSlice(1); selectPic(origPid); selectSlice(1); end; end; macro '[x] expand'; var i, n: integer; begin selectPic(newPid); choosePic(vectPid); if nSlices = 0 then ExpMask16u(vectPid, maskPid, newPid) else n := nSlices; for i := 1 to n do begin choosePic(vectPid); chooseSlice(i); ExpMask16u(vectPid, maskPid,newPid); selectPic(newPid); selectAll; KillROI; {forces update} end; end; end; macro '[c] convert and expand 16u to 8'; var i, n: integer; begin selectPic(newPid); choosePic(vectPid); if nSlices = 0 then CnvMsk16uTo8(vectPid,xlate16uto8Pid,maskPid, newPid) else n := nSlices; for i := 1 to n do begin choosePic(vectPid); chooseSlice(i); CnvMsk16uTo8(vectPid,xlate16uto8Pid,maskPid, newPid); selectPic(newPid); selectAll; KillROI; {forces update} end; end; end; macro 'convert front 8 bit image to 16 bits'; var i: integer; inPid, xlatePid, outPid: integer; width, height: integer; begin SaveState; inPid := pidNumber; GetPicSize(width,height); SetNewSize(512,1); SetBackgroundColor(0); MakeNewWindow('8 to 16 conversion table'); xlatePid := pidNumber; for i := 0 to 255 do putpixel(i*2,0,i); MakeRoi(0,0,512,1); SetNewSize(width*2,height); MakeNewWindow('16 bit image from ',inPid:0); outPid := pidNumber; RestoreState; Cnvrt8to16u(inPid,xlatePid,outPid); end; macro 'front image is 16 to 8 conversion table'; begin xlate16uto8Pid := pidNumber; end; macro 'set 16 to 8 conversion parameters'; begin ymin := GetNumber('minimum 8 bit pixel value',1); ymax := GetNumber('maximum 8 bit pixel value',254); end; macro 'make 16 to 8 conversion table'; var i,j, x, y: integer; width, height: integer; inPid, min,max: integer; begin RequiresUser('pixel16u',1); if ymax = 0 then begin ymin := GetNumber('minimum 8 bit pixel value',1); ymax := GetNumber('maximum 8 bit pixel value',254); end; SaveState; inPid := pidNumber; minMax16u(inPid,min,max); SetNewSize(256,256); SetBackgroundColor(0); MakeNewWindow('16 to 8 conversion table'); xlate16uto8Pid := pidNumber; linLUT16uto8(xlate16uto8Pid,min,max,ymin,ymax); end; macro 'convert front 16 bit image to 8 bits'; var i,j, x, y: integer; inPid, outPid: integer; width, height: integer; min,max: integer; begin RequiresUser('pixel16u',1); inPid := pidNumber; GetPicSize(width,height); SaveState; ChoosePic(xlate16uto8Pid); MakeRoi(0,0,256,256); SetNewSize(width div 2,height); MakeNewWindow('8 bit image from ',inPid:0); outPid := pidNumber; RestoreState; Cnvrt16uto8(inPid,xlate16uto8Pid,outPid); end;